Skip to content

Conversation

@SpriteOvO
Copy link
Member

@SpriteOvO SpriteOvO commented Jan 14, 2026

Tracking issue: #146922 #![feature(type_info)]

This PR supports ADT types for feature type_info reflection.
(It's still a draft PR, with implementation in progress)

Note that this PR does not take SemVer into consideration (I left a FIXME comment). As discussed earlier (comment), this requires further discussion. However, I hope we could get an initial implementation to land first, so we can start playing with it.

Progress / Checklist

r? @oli-obk

@SpriteOvO SpriteOvO added A-type-system Area: Type system F-type_info #![feature(type_info)] labels Jan 14, 2026
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@SpriteOvO SpriteOvO changed the title Support primitives in type info reflection Support ADT types in type info reflection Jan 14, 2026
Comment on lines 236 to 288
sym::name => {
if let Some(name) = name {
let name_place = self.allocate_str_dedup(name.as_str())?;
let ptr = self.mplace_to_ref(&name_place)?;
self.write_immediate(*ptr, &field_place)?
} else {
let (variant, _) = self.downcast(&field_place, sym::None)?;
self.write_discriminant(variant, &field_place)?;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like I should write sym::Some discriminant for name? 🤔 Writing ptr directly seems to work, but this relies on how Option<&'static str> is underlyingly represented IIUC.

But const eval interpreter doesn't complain about this -- perhaps it should?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the interpreter doesn't care if the value is exactly the same as if it had its discriminant written. There is some talk about SetDiscriminant needing to happen always, but it's not really important for us here, this will be fixed by whoever changes it

also irrelevant if we make the field just always have a name (rendering the index)

@rust-log-analyzer

This comment has been minimized.

#[non_exhaustive]
#[unstable(feature = "type_info", issue = "146922")]
pub struct Field {
/// The name of the struct.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the field's name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also make it non-optional and produce integer names for tuples and tuple structs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that was a typo.

could also make it non-optional and produce integer names for tuples and tuple structs

Good idea.

Comment on lines 236 to 288
sym::name => {
if let Some(name) = name {
let name_place = self.allocate_str_dedup(name.as_str())?;
let ptr = self.mplace_to_ref(&name_place)?;
self.write_immediate(*ptr, &field_place)?
} else {
let (variant, _) = self.downcast(&field_place, sym::None)?;
self.write_discriminant(variant, &field_place)?;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the interpreter doesn't care if the value is exactly the same as if it had its discriminant written. There is some talk about SetDiscriminant needing to happen always, but it's not really important for us here, this will be fixed by whoever changes it

also irrelevant if we make the field just always have a name (rendering the index)

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-type-system Area: Type system F-type_info #![feature(type_info)] S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants